package test;

import java.util.*;
import java.io.*;

public class SampleSearchLog {

	static String slPath = "final.txt";
	static String outPath = "sample.txt";
	static int sampleThreshold = 200000;
	
	public static void main(String[] args) {
		try {
			FileInputStream fis = new FileInputStream(slPath);
			DataInputStream dis = new DataInputStream(fis);
			BufferedReader br = new BufferedReader(new InputStreamReader(dis));
			BufferedWriter bw = new BufferedWriter(new FileWriter(outPath));
			String line = br.readLine();
			int count = 0;
			while (line != null && !line.equals("")) {
				if (line.split("\t").length == 4) {
					outLine(line);
					if (++count == sampleThreshold) 
						break;
				}
				line = br.readLine();
			}
			System.out.println(sampleThreshold + " samples are included! ");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	static BufferedWriter bw;
	private static void outLine(String line) {
		try {
			if (bw == null) {
				bw = new BufferedWriter(new FileWriter(outPath));
			}
			bw.write(line); bw.newLine();
			bw.flush();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
